<?php
    /**
     * User zgh
     * Email 1803897171@qq.com
     * Date 2021/7/20
     **/

    namespace app\admin\controller;


    use app\admin\service\NodeService;
    use app\common\Annotation\ControllerAnnotation;
    use app\common\Annotation\NodeAnotation;
    use app\common\controller\BackendController;
    use app\common\model\SystemNodeModel;
    use think\facade\Request;
    /**
     * @ControllerAnnotation(title="节点管理",auth=2)
     * Class NodeController
     * @package app\admin\controller
     */
    class NodeController extends BackendController
    {
        /**
         * @NodeAnotation(title="列表")
         * @return mixed|\think\response\Json
         */
        public function index()
        {
            if (Request::isAjax()) {
                $model = new SystemNodeModel();
                $count = $model->count();
                $list = $model->getNodeTreeList();
                return success_json_response("成功", $list, ['count' => $count]);
            } else {
                return $this->fetch();
            }
        }

        /**
         * @NodeAnotation(title="刷新节点")
         * @return \think\response\Json
         */
        public function refresh()
        {
            $res = NodeService::refresh(Request::param());
            if ($res) {
                return success_json_response("更新成功");
            } else {
                return json_response("更新失败");
            }
        }
    }